package ir_v3

import (
	"github.com/astaxie/beego/orm"
	"time"
)

type PhysicalZone struct {
	Id         int       `orm:"Column(Id)"`
	MallId     string    `orm:"Column(MallId)"`
	UpdateTime time.Time `orm:"Column(UpdateTime)"`
	Name       string    `orm:"Column(Name)"`
	UpdateUser string    `orm:"Column(UpdateUser)"`
	ZoneTypeId string    `orm:"Column(ZoneTypeId)"`
	Enabled    int       `orm:"Column(Enabled)"`
	Rank       int       `orm:"Column(Rank)"`
}

func (u *PhysicalZone) TableName() string {
	return PhysicalZoneTBName()
}

func InsertPhysicalZone(p PhysicalZone) (int64, error) {
	o := orm.NewOrm()
	return o.InsertOrUpdate(&p)
}

func FindAllPhysicalZone() (*[]PhysicalZone, error) {
	o := orm.NewOrm()
	qs := o.QueryTable(PhysicalZoneTBName())
	pzs := new([]PhysicalZone)
	_, err := qs.All(pzs)
	return pzs, err
}

func SelectPhysicalZoneByName(name string) (PhysicalZone, error) {
	o := orm.NewOrm()
	var pz PhysicalZone
	err := o.Raw("SELECT * FROM d_physicalzones WHERE `Name` = ?;", name).QueryRow(&pz)
	return pz, err
}
